#ifndef  GLIB_GRAPHICS_HY
#define  GLIB_GRAPHICS_HY


#include "gMatrix.h"
#include "gCamera.h"
#include "utility.h"
#include "gDefines.h"
#include "gRenderList.h"

class CEngine;
class CTriangle;

#define MAX_VERTEX_NUM   1024
#define MAX_FACE_NUM  4096

class CGraphics
{
private:
	CEngine *m_engine;

	unsigned int m_color;
	CMath m_mathTool;
	CGLIBMatrix m_matModel;
	CRenderList m_renderList;

public:
	CCameraELUER m_camera;

public:
	CGraphics(CEngine *engine);
	~CGraphics();
	
	void gInitialize();
	void gSetColor(unsigned char r, unsigned char g, unsigned char b);

	int  gClipLine(int &x1,int &y1,int &x2, int &y2);
	int  gDrawLine32(int x_start, int y_start, int x_end, int y_end, bool useClip = true);
	void gDrawTriangle32(int x1, int y1, int x2, int y2, int x3, int y3);
	void gDrawTriangle32(CTriangleVertex *tri);
	int  gFillRect32(int x_start, int y_start, int width, int height);
	void gDrawClipRect();

	void gInsertToRenderList(CTriangleIndex *tri);
	void gDrawRenderList();
	void gResetRenderList();

	void gTranslate(int tx, int ty, int tz = 0);
	void gRotateX(int rx);
	void gRotateY(int ry);
	void gRotateZ(int rz);
	void gScale(int sx, int sy, int sz = 1);

	void gTranslateToWorldCoord(gVertex3D *des, gVertex3D *src, int vertexNum);
	void gTranslateToCameraCoord(gVertex3D *vbuffer, gVertex3D::VertexState *vertexStateBuff, int vertexNum);
	void gApplyProject();
	void gTranslateToViewport();

	void gLoadIdentity();
	void gPushMatrix();
	void gPopMatrix();

	void gSetViewPosX(int x);
	void gSetViewPosY(int y);
	void gSetViewPosZ(int z);
	void gSetViewWidth(int w);
	void gSetViewHeight(int h);

	int gGetViewPosX();
	int gGetViewPosY();
	int gGetViewPosZ();
	int gGetViewWidth();
	int gGetViewHeight();
};

#endif